package ace.module.mail.address.core.impl.api.impl;

import ace.cmp.core.model.PageResultDto;
import ace.cmp.core.model.R;
import ace.module.common.api.annotation.ApiLocalPriority;
import ace.module.common.api.model.input.TenantAndAppTypeInput;
import ace.module.common.core.impl.api.impl.SdkApiImpl;
import ace.module.mail.address.api.MadMailAddressApi;
import ace.module.mail.address.api.model.dto.MadMailAddressDto;
import ace.module.mail.address.api.model.input.mailaddress.MadMailAddressAddInput;
import ace.module.mail.address.api.model.input.mailaddress.MadMailAddressModifyInput;
import ace.module.mail.address.api.model.input.mailaddress.MadMailAddressSearchInput;
import ace.module.mail.address.core.impl.dao.entity.MadMailAddress;
import ace.module.mail.address.core.impl.manager.MadMailAddressManager;
import ace.module.mail.address.core.impl.service.MadMailAddressService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;


/**
 * 邮寄地址 api implements.
 *
 * @author Caspar
 *
 */
@ApiLocalPriority
@AllArgsConstructor
@Component
public class MadMailAddressApiImpl
    extends SdkApiImpl<MadMailAddress, Long, MadMailAddressDto, MadMailAddressManager>
    implements MadMailAddressApi {

  private final MadMailAddressService madMailAddressService;

  @Override
  public R<PageResultDto<MadMailAddressDto>> search(MadMailAddressSearchInput input) {
    PageResultDto<MadMailAddressDto> result = madMailAddressService.search(input);
    return R.ok(result);
  }

  @Override
  public R<Long> addByAppOutId(MadMailAddressAddInput input) {
    Long id = madMailAddressService.addByAppOutId(input);
    return R.ok(id);
  }

  @Override
  public R<Void> modifyByAppOutId(MadMailAddressModifyInput input) {
    madMailAddressService.modifyByAppOutId(input);
    return R.ok();
  }

  @Override
  public R<MadMailAddressDto> getByTenantAndAppTypeAndId(TenantAndAppTypeInput<Long> input) {
    MadMailAddressDto madMailAddressDto = madMailAddressService.getByTenantAndAppTypeAndId(input);
    return R.ok(madMailAddressDto);
  }
}
